﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CTPAdapter;

namespace Galaxy_Q_Trader
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        public CSTraderApi objTrader;
        private void button1_Click(object sender, EventArgs e)
        {

            objTrader = new CSTraderApi("test", false);
            CSTraderSpiInter objCSTraderSpi = new CSTraderSpi();
            objTrader.RegisterSpi(objCSTraderSpi);
            objTrader.SubscribePublicTopic(CSTHOST_TE_RESUME_TYPE.CSTHOST_TERT_QUICK);
            objTrader.SubscribePrivateTopic(CSTHOST_TE_RESUME_TYPE.CSTHOST_TERT_QUICK);
            objTrader.RegisterFront("tcp://asp-sim2-front1.financial-trading-platform.com:26205");
            objTrader.Init();
            //string xxx = obj.GetTradingDay();
            //obj.Join();
            //obj.Release();


        //// 初始化UserApi
        //pUserApi = CThostFtdcTraderApi::CreateFtdcTraderApi(){}			// 创建UserApi
        //pUserSpi = new CTraderSpi(_AdapterConfig->ctpSpi){}
        //pUserApi->RegisterSpi((CThostFtdcTraderSpi*)pUserSpi){}			// 注册事件类
        //pUserApi->SubscribePublicTopic(THOST_TERT_QUICK){}					// 注册公有流
        //pUserApi->SubscribePrivateTopic(THOST_TERT_QUICK){}					// 注册私有流
        //pUserApi->RegisterFront(FRONT_ADDR){}							// connect
        //pUserApi->Init(){}

        }
        public CSMdApi obj;
        private void button2_Click(object sender, EventArgs e)
        {
           obj = new CSMdApi("", false);
            CSMdSpiInter objCSMdSpi = new CSMdSpi();
            obj.RegisterSpi(objCSMdSpi);
            //obj.SubscribePublicTopic(CSTHOST_TE_RESUME_TYPE.CSTHOST_TERT_QUICK);
            //obj.SubscribePrivateTopic(CSTHOST_TE_RESUME_TYPE.CSTHOST_TERT_QUICK);
            obj.RegisterFront("tcp://asp-sim2-md1.financial-trading-platform.com:26213");
            obj.Init();

            
            //string xxx = obj.GetTradingDay();

            //obj.Join();
            //obj.Release();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string s1 = "";
            byte[] sb = new byte[2];
            sb[0] = (byte)CSTThostFtdcContingentConditionType.CSTHOST_FTDC_CC_Immediately;
            s1 = System.Text.ASCIIEncoding.ASCII.GetString(sb);
            
            
        }
            
    }



    public class CSTraderSpi:CSTraderSpiInter
    {

        private bool IsErrorRspInfo(CSCThostFtdcRspInfoField pRspInfo)
        {
            // 如果ErrorID != 0, 说明收到了错误的响应
            bool bResult = false;
            if (pRspInfo != null && pRspInfo.ErrorID != 0)
            {

                bResult = true;

            }
            if (bResult)
            {
                int de = 6;
            }
            return bResult;
        }

        int FRONT_ID = 0;
        int SESSION_ID = 0;
        string  ORDER_REF = ""; 
        int iNextOrderRef = 0;


		///当客户端与交易后台建立起通信连接时（还未登录前），该方法被调用。
		public void OnFrontConnected()
        {

            CSCThostFtdcReqUserLoginField req = new CSCThostFtdcReqUserLoginField(); ;
            req.BrokerID = "2030";
            req.UserID = "351966";
            req.Password = "888888";

            Program.frm1.objTrader.ReqUserLogin(req);              

                 
            
        }

			///当客户端与交易后台通信连接断开时，该方法被调用。当发生这个情况后，API会自动重新连接，客户端可不做处理。
			///@param nReason 错误原因
			///        0x1001 网络读失败
			///        0x1002 网络写失败
			///        0x2001 接收心跳超时
			///        0x2002 发送心跳失败
			///        0x2003 收到错误报文
			public void OnFrontDisconnected(int nReason){}

			///心跳超时警告。当长时间未收到报文时，该方法被调用。
			///@param nTimeLapse 距离上次接收报文的时间
			public void OnHeartBeatWarning(int nTimeLapse){}

			///客户端认证响应
			public void OnRspAuthenticate(CSCThostFtdcRspAuthenticateField  pRspAuthenticateField, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}


			///登录请求响应
			public void OnRspUserLogin(CSCThostFtdcRspUserLoginField  pRspUserLogin, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) 
            {


                if (bIsLast && !IsErrorRspInfo(pRspInfo))
                {
                    // 保存会话参数
                    FRONT_ID = pRspUserLogin.FrontID;
                    SESSION_ID = pRspUserLogin.SessionID;
                    iNextOrderRef = Int32.Parse(pRspUserLogin.MaxOrderRef);
                    iNextOrderRef++;
                    ORDER_REF = iNextOrderRef.ToString();
                    //sprintf(ORDER_REF, "%d", iNextOrderRef);
                    ///获取当前交易日
                    //cerr << "--->>> 获取当前交易日 = " << pUserApi->GetTradingDay() << endl;
                    ///投资者结算结果确认
                    ReqSettlementInfoConfirm();
                }          
            
            }     
        ///投资者结算结果确认
        void ReqSettlementInfoConfirm()
        {
	        CSCThostFtdcSettlementInfoConfirmField req = new CSCThostFtdcSettlementInfoConfirmField();
	        //memset(&req, 0, sizeof(req));
            req.BrokerID = "2030";
            req.InvestorID = "351966";
	        //strcpy(req.BrokerID, BROKER_ID);
	        //strcpy(req.InvestorID, INVESTOR_ID);
	        int iResult = Program.frm1.objTrader.ReqSettlementInfoConfirm(req);
	        //cerr << "--->>> 投资者结算结果确认: " << ((iResult == 0) ? "成功" : "失败") << endl;
        }          
            
            
            
 








			///登出请求响应
			public void OnRspUserLogout(CSCThostFtdcUserLogoutField  pUserLogout, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///用户口令更新请求响应
			public void OnRspUserPasswordUpdate(CSCThostFtdcUserPasswordUpdateField  pUserPasswordUpdate, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///资金账户口令更新请求响应
			public void OnRspTradingAccountPasswordUpdate(CSCThostFtdcTradingAccountPasswordUpdateField  pTradingAccountPasswordUpdate, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///报单录入请求响应
			public void OnRspOrderInsert(CSCThostFtdcInputOrderField  pInputOrder, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast)
            {

                int xxx = 35;

            }

			///预埋单录入请求响应
			public void OnRspParkedOrderInsert(CSCThostFtdcParkedOrderField  pParkedOrder, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///预埋撤单录入请求响应
			public void OnRspParkedOrderAction(CSCThostFtdcParkedOrderActionField  pParkedOrderAction, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///报单操作请求响应
			public void OnRspOrderAction(CSCThostFtdcInputOrderActionField  pInputOrderAction, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///查询最大报单数量响应
			public void OnRspQueryMaxOrderVolume(CSCThostFtdcQueryMaxOrderVolumeField  pQueryMaxOrderVolume, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///投资者结算结果确认响应
			public void OnRspSettlementInfoConfirm(CSCThostFtdcSettlementInfoConfirmField  pSettlementInfoConfirm, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast)
            {


                //cerr << "--->>> " << "OnRspSettlementInfoConfirm" << endl;
                if (bIsLast && !IsErrorRspInfo(pRspInfo))
                {
                    ///请求查询合约
                    ReqQryInstrument();
                }



            }

            ///请求查询合约
            void ReqQryInstrument()
            {
	            CSCThostFtdcQryInstrumentField req = new CSCThostFtdcQryInstrumentField();
	            //memset(&req, 0, sizeof(req));
	            req.InstrumentID="IF1205";
                int iResult = Program.frm1.objTrader.ReqQryInstrument(req);
	            //cerr << "--->>> 请求查询合约: " << ((iResult == 0) ? "成功" : "失败") << endl;
            }

			///删除预埋单响应
			public void OnRspRemoveParkedOrder(CSCThostFtdcRemoveParkedOrderField  pRemoveParkedOrder, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///删除预埋撤单响应
			public void OnRspRemoveParkedOrderAction(CSCThostFtdcRemoveParkedOrderActionField  pRemoveParkedOrderAction, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询报单响应
			public void OnRspQryOrder(CSCThostFtdcOrderField  pOrder, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询成交响应
			public void OnRspQryTrade(CSCThostFtdcTradeField  pTrade, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询投资者持仓响应
			public void OnRspQryInvestorPosition(CSCThostFtdcInvestorPositionField  pInvestorPosition, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast)
            {
                if (bIsLast && !IsErrorRspInfo(pRspInfo))
                {
                    ///报单录入请求
                    ReqOrderInsert();
                }


            }

            void ReqOrderInsert()
            {
	            CSCThostFtdcInputOrderField req = new CSCThostFtdcInputOrderField();
	            //memset(&req, 0, sizeof(req));
	            ///经纪公司代码
	            //strcpy(req.BrokerID, BROKER_ID);
                req.BrokerID = "2030";
	            ///投资者代码
	            //strcpy(req.InvestorID, INVESTOR_ID);
                req.InvestorID = "351966";
	            ///合约代码
	            //strcpy(req.InstrumentID, INSTRUMENT_ID);
                req.InstrumentID = "IF1205";
	            ///报单引用
	            //strcpy(req.OrderRef, ORDER_REF);
                req.OrderRef = ORDER_REF;
	            ///用户代码
                //	TThostFtdcUserIDType	UserID;
	            ///报单价格条件: 限价
                req.OrderPriceType = (sbyte)CSTThostFtdcOrderPriceTypeType.CSTHOST_FTDC_OPT_LimitPrice;
	            ///买卖方向: 
                req.Direction = (sbyte)CSTThostFtdcDirectionType.CSTHOST_FTDC_D_Sell;
	            ///组合开平标志: 开仓

                //req.CombOffsetFlag = ((sbyte)CSTThostFtdcOffsetFlagType.CSTHOST_FTDC_OF_Open).ToString();
                req.CombOffsetFlag = ASCIIEncoding.ASCII.GetString(new byte[]{(byte)CSTThostFtdcOffsetFlagType.CSTHOST_FTDC_OF_Open});
	            ///组合投机套保标志 
                req.CombHedgeFlag = ASCIIEncoding.ASCII.GetString(new byte[] { (byte)CSTThostFtdcHedgeFlagType.CSTHOST_FTDC_HF_Speculation });
	            ///价格
	            req.LimitPrice = 2500;
	            ///数量: 1
	            req.VolumeTotalOriginal = 1;
	            ///有效期类型: 当日有效
                req.TimeCondition = (sbyte)CSTThostFtdcTimeConditionType.CSTHOST_FTDC_TC_GFD;
	            ///GTD日期
            //	TThostFtdcDateType	GTDDate;
	            ///成交量类型: 任何数量
                req.VolumeCondition = (sbyte)CSTThostFtdcVolumeConditionType.CSTHOST_FTDC_VC_AV;
	            ///最小成交量: 1
	            req.MinVolume = 1;
	            ///触发条件: 立即
                req.ContingentCondition = (sbyte)CSTThostFtdcContingentConditionType.CSTHOST_FTDC_CC_Immediately;
	            ///止损价
            //	TThostFtdcPriceType	StopPrice;
	            ///强平原因: 非强平
                req.ForceCloseReason = (sbyte)CSTThostFtdcForceCloseReasonType.CSTHOST_FTDC_FCC_NotForceClose;
	            ///自动挂起标志: 否
	            req.IsAutoSuspend = 0;
	            ///业务单元
            //	TThostFtdcBusinessUnitType	BusinessUnit;
	            ///请求编号
            //	TThostFtdcRequestIDType	RequestID;
	            ///用户强评标志: 否
	            req.UserForceClose = 0;

                int iResult = Program.frm1.objTrader.ReqOrderInsert(req);
	            //cerr << "--->>> 报单录入请求: " << ((iResult == 0) ? "成功" : "失败") << endl;
            }       

			///请求查询资金账户响应
			public void OnRspQryTradingAccount(CSCThostFtdcTradingAccountField  pTradingAccount, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast)
            {
                if (bIsLast && !IsErrorRspInfo(pRspInfo))
                {
		            ///请求查询投资者持仓
		            ReqQryInvestorPosition();
                }

            }

            void ReqQryInvestorPosition()
            {
	            CSCThostFtdcQryInvestorPositionField req = new CSCThostFtdcQryInvestorPositionField();
	            //memset(&req, 0, sizeof(req));
	            //strcpy(req.BrokerID, BROKER_ID);
	            //strcpy(req.InvestorID, INVESTOR_ID);
	            //strcpy(req.InstrumentID, INSTRUMENT_ID);
                req.BrokerID = "2030";
                req.InvestorID = "351966";
                req.InstrumentID = "IF1205";
                int iResult = Program.frm1.objTrader.ReqQryInvestorPosition(req);
	            //cerr << "--->>> 请求查询投资者持仓: " << ((iResult == 0) ? "成功" : "失败") << endl;
            }

			///请求查询投资者响应
			public void OnRspQryInvestor(CSCThostFtdcInvestorField  pInvestor, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询交易编码响应
			public void OnRspQryTradingCode(CSCThostFtdcTradingCodeField  pTradingCode, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询合约保证金率响应
			public void OnRspQryInstrumentMarginRate(CSCThostFtdcInstrumentMarginRateField  pInstrumentMarginRate, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询合约手续费率响应
			public void OnRspQryInstrumentCommissionRate(CSCThostFtdcInstrumentCommissionRateField  pInstrumentCommissionRate, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询交易所响应
			public void OnRspQryExchange(CSCThostFtdcExchangeField  pExchange, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询合约响应
			public void OnRspQryInstrument(CSCThostFtdcInstrumentField  pInstrument, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast)
            {
                if (bIsLast && !IsErrorRspInfo(pRspInfo))
                {
                    ///请求查询资金
                    ReqQryTradingAccount();
                }

            }


            void ReqQryTradingAccount()
            {
	            CSCThostFtdcQryTradingAccountField req = new CSCThostFtdcQryTradingAccountField();
	            //memset(&req, 0, sizeof(req));
	            //strcpy(req.BrokerID, BROKER_ID);
	            //strcpy(req.InvestorID, INVESTOR_ID);
                req.BrokerID = "2030";
                req.InvestorID = "351966";

                int iResult = Program.frm1.objTrader.ReqQryTradingAccount(req);
	            //cerr << "--->>> 请求查询资金账户: " << ((iResult == 0) ? "成功" : "失败") << endl;
            }


			///请求查询行情响应
			public void OnRspQryDepthMarketData(CSCThostFtdcDepthMarketDataField  pDepthMarketData, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询投资者结算结果响应
			public void OnRspQrySettlementInfo(CSCThostFtdcSettlementInfoField  pSettlementInfo, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询转帐银行响应
			public void OnRspQryTransferBank(CSCThostFtdcTransferBankField  pTransferBank, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询投资者持仓明细响应
			public void OnRspQryInvestorPositionDetail(CSCThostFtdcInvestorPositionDetailField  pInvestorPositionDetail, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询客户通知响应
			public void OnRspQryNotice(CSCThostFtdcNoticeField  pNotice, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询结算信息确认响应
			public void OnRspQrySettlementInfoConfirm(CSCThostFtdcSettlementInfoConfirmField  pSettlementInfoConfirm, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询投资者持仓明细响应
			public void OnRspQryInvestorPositionCombineDetail(CSCThostFtdcInvestorPositionCombineDetailField  pInvestorPositionCombineDetail, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///查询保证金监管系统经纪公司资金账户密钥响应
			public void OnRspQryCFMMCTradingAccountKey(CSCThostFtdcCFMMCTradingAccountKeyField  pCFMMCTradingAccountKey, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询仓单折抵信息响应
			public void OnRspQryEWarrantOffset(CSCThostFtdcEWarrantOffsetField  pEWarrantOffset, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询转帐流水响应
			public void OnRspQryTransferSerial(CSCThostFtdcTransferSerialField  pTransferSerial, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询银期签约关系响应
			public void OnRspQryAccountregister(CSCThostFtdcAccountregisterField  pAccountregister, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///错误应答
			public void OnRspError(CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///报单通知
			public void OnRtnOrder(CSCThostFtdcOrderField  pOrder) {}

			///成交通知
			public void OnRtnTrade(CSCThostFtdcTradeField  pTrade) {}

			///报单录入错误回报
			public void OnErrRtnOrderInsert(CSCThostFtdcInputOrderField  pInputOrder, CSCThostFtdcRspInfoField  pRspInfo) {}

			///报单操作错误回报
			public void OnErrRtnOrderAction(CSCThostFtdcOrderActionField  pOrderAction, CSCThostFtdcRspInfoField  pRspInfo) {}

			///合约交易状态通知
			public void OnRtnInstrumentStatus(CSCThostFtdcInstrumentStatusField  pInstrumentStatus) {}

			///交易通知
			public void OnRtnTradingNotice(CSCThostFtdcTradingNoticeInfoField  pTradingNoticeInfo) {}

			///提示条件单校验错误
			public void OnRtnErrorConditionalOrder(CSCThostFtdcErrorConditionalOrderField  pErrorConditionalOrder) {}

			///请求查询签约银行响应
			public void OnRspQryContractBank(CSCThostFtdcContractBankField  pContractBank, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询预埋单响应
			public void OnRspQryParkedOrder(CSCThostFtdcParkedOrderField  pParkedOrder, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询预埋撤单响应
			public void OnRspQryParkedOrderAction(CSCThostFtdcParkedOrderActionField  pParkedOrderAction, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询交易通知响应
			public void OnRspQryTradingNotice(CSCThostFtdcTradingNoticeField  pTradingNotice, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询经纪公司交易参数响应
			public void OnRspQryBrokerTradingParams(CSCThostFtdcBrokerTradingParamsField  pBrokerTradingParams, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///请求查询经纪公司交易算法响应
			public void OnRspQryBrokerTradingAlgos(CSCThostFtdcBrokerTradingAlgosField  pBrokerTradingAlgos, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///银行发起银行资金转期货通知
			public void OnRtnFromBankToFutureByBank(CSCThostFtdcRspTransferField  pRspTransfer) {}

			///银行发起期货资金转银行通知
			public void OnRtnFromFutureToBankByBank(CSCThostFtdcRspTransferField  pRspTransfer) {}

			///银行发起冲正银行转期货通知
			public void OnRtnRepealFromBankToFutureByBank(CSCThostFtdcRspRepealField  pRspRepeal) {}

			///银行发起冲正期货转银行通知
			public void OnRtnRepealFromFutureToBankByBank(CSCThostFtdcRspRepealField  pRspRepeal) {}

			///期货发起银行资金转期货通知
			public void OnRtnFromBankToFutureByFuture(CSCThostFtdcRspTransferField  pRspTransfer) {}

			///期货发起期货资金转银行通知
			public void OnRtnFromFutureToBankByFuture(CSCThostFtdcRspTransferField  pRspTransfer) {}

			///系统运行时期货端手工发起冲正银行转期货请求，银行处理完毕后报盘发回的通知
			public void OnRtnRepealFromBankToFutureByFutureManual(CSCThostFtdcRspRepealField  pRspRepeal) {}

			///系统运行时期货端手工发起冲正期货转银行请求，银行处理完毕后报盘发回的通知
			public void OnRtnRepealFromFutureToBankByFutureManual(CSCThostFtdcRspRepealField  pRspRepeal) {}

			///期货发起查询银行余额通知
			public void OnRtnQueryBankBalanceByFuture(CSCThostFtdcNotifyQueryAccountField  pNotifyQueryAccount) {}

			///期货发起银行资金转期货错误回报
			public void OnErrRtnBankToFutureByFuture(CSCThostFtdcReqTransferField  pReqTransfer, CSCThostFtdcRspInfoField  pRspInfo) {}

			///期货发起期货资金转银行错误回报
			public void OnErrRtnFutureToBankByFuture(CSCThostFtdcReqTransferField  pReqTransfer, CSCThostFtdcRspInfoField  pRspInfo) {}

			///系统运行时期货端手工发起冲正银行转期货错误回报
			public void OnErrRtnRepealBankToFutureByFutureManual(CSCThostFtdcReqRepealField  pReqRepeal, CSCThostFtdcRspInfoField  pRspInfo) {}

			///系统运行时期货端手工发起冲正期货转银行错误回报
			public void OnErrRtnRepealFutureToBankByFutureManual(CSCThostFtdcReqRepealField  pReqRepeal, CSCThostFtdcRspInfoField  pRspInfo) {}

			///期货发起查询银行余额错误回报
			public void OnErrRtnQueryBankBalanceByFuture(CSCThostFtdcReqQueryAccountField  pReqQueryAccount, CSCThostFtdcRspInfoField  pRspInfo) {}

			///期货发起冲正银行转期货请求，银行处理完毕后报盘发回的通知
			public void OnRtnRepealFromBankToFutureByFuture(CSCThostFtdcRspRepealField  pRspRepeal) {}

			///期货发起冲正期货转银行请求，银行处理完毕后报盘发回的通知
			public void OnRtnRepealFromFutureToBankByFuture(CSCThostFtdcRspRepealField  pRspRepeal) {}

			///期货发起银行资金转期货应答
			public void OnRspFromBankToFutureByFuture(CSCThostFtdcReqTransferField  pReqTransfer, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///期货发起期货资金转银行应答
			public void OnRspFromFutureToBankByFuture(CSCThostFtdcReqTransferField  pReqTransfer, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///期货发起查询银行余额应答
			public void OnRspQueryBankAccountMoneyByFuture(CSCThostFtdcReqQueryAccountField  pReqQueryAccount, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

			///银行发起银期开户通知
			public void OnRtnOpenAccountByBank(CSCThostFtdcOpenAccountField  pOpenAccount) {}

			///银行发起银期销户通知
			public void OnRtnCancelAccountByBank(CSCThostFtdcCancelAccountField  pCancelAccount) {}

			///银行发起变更银行账号通知
			public void OnRtnChangeAccountByBank(CSCThostFtdcChangeAccountField  pChangeAccount) {}





    }
    class CSMdSpi : CSMdSpiInter
    {
		///当客户端与交易后台建立起通信连接时（还未登录前），该方法被调用。
        public void OnFrontConnected()
        {

            CSCThostFtdcReqUserLoginField req = new CSCThostFtdcReqUserLoginField();
            req.BrokerID = "2030";
            req.UserID = "351966";
            req.Password = "888888";

            Program.frm1.obj.ReqUserLogin(req);
        }

		///当客户端与交易后台通信连接断开时，该方法被调用。当发生这个情况后，API会自动重新连接，客户端可不做处理。
		///@param nReason 错误原因
		///        0x1001 网络读失败
		///        0x1002 网络写失败
		///        0x2001 接收心跳超时
		///        0x2002 发送心跳失败
		///        0x2003 收到错误报文
		public void OnFrontDisconnected(int nReason){}

		///心跳超时警告。当长时间未收到报文时，该方法被调用。
		///@param nTimeLapse 距离上次接收报文的时间
		public void OnHeartBeatWarning(int nTimeLapse){}


		///登录请求响应
		public void OnRspUserLogin(CSCThostFtdcRspUserLoginField  pRspUserLogin, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast)
        {
            int qa = 0;

            string[] strTemp = new string[2];
            strTemp[0] = "IF1205";
            strTemp[1] = "IF1206";
            int XXX =  Program.frm1.obj.SubscribeMarketData(strTemp, 2);

        }

		///登出请求响应
		public void OnRspUserLogout(CSCThostFtdcUserLogoutField  pUserLogout, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

		///错误应答
		public void OnRspError(CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

		///订阅行情应答
		public void OnRspSubMarketData(CSCThostFtdcSpecificInstrumentField  pSpecificInstrument, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

		///取消订阅行情应答
		public void OnRspUnSubMarketData(CSCThostFtdcSpecificInstrumentField  pSpecificInstrument, CSCThostFtdcRspInfoField  pRspInfo, int nRequestID, bool bIsLast) {}

		///深度行情通知
        public void OnRtnDepthMarketData(CSCThostFtdcDepthMarketDataField pDepthMarketData)
        {
            int xxx = 5;


        }


    }
}
